<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>菜单管理</title>
<link href="style/css.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> 
<script src="js/My97DatePicker/WdatePicker.js"
      type="text/javascript"></script> 
<script src="js/jquery.blockUI.js" type="text/javascript"></script>
<script type="text/javascript"> 
$(document).ready(function(){


  var riqinian=$("#riqiNian").val();
  var riqiyue=$("#riqiYue").val();
$.ajax({ 
    type:'post', //传送的方式,get/post 
    url:'getAllShopMarketing.php', //发送数据的地址 
    cache:'false', 
    data:'riqinian='+riqinian+"&riqiyue="+riqiyue, 
    dataType: 'text',
    success:function(data) 
    { 
      var hi=data.split(",");
      $("#fenshu").html(hi[1]);
      $("#jiage").html(hi[0]);
    }
  }); 

});

function getAllOrderMoney(sid){
  var riqinian=$("#riqiNian").val();
  var riqiyue=$("#riqiYue").val();
  $.ajax({ 
    type:'post', //传送的方式,get/post 
    url:'getAllShopMarketing.php', //发送数据的地址 
    cache:'false', 
    data:'riqinian='+riqinian+"&riqiyue="+riqiyue+"&sid="+sid, 
    dataType: 'text',
    success:function(data) 
    { 
      var hi=data.split(",");
      $("#fenshu").html(hi[1]);
      $("#jiage").html(hi[0]);
    }
  });
}
function addMenue(bid,sid){
  var bid=bid;
  var sid=sid;
  var menueName=$("#menueName"+bid).val();
  var menueNum=$("#menueNum"+bid).val();

  if(menueName.length>0&&menueNum.length>0){

  }else{
alert("请插入正确值");
return;
  }
  $.ajax({ 
    type:'post', //传送的方式,get/post 
    url:'menueAjax.php', //发送数据的地址 
    cache:'false', 
    data:'bid='+bid+"&menueName="+menueName+"&menueNum="+menueNum+"&sid="+sid+"&which=0", 
    datatype:"text",
    success:function(data) 
    { 
      window.location.reload();
    } 
  }); 
}


function addBigMenue(supplier_location_id){
  alert(supplier_location_id);

  var menueName=$("#menueBigbName").val();
  if(menueName.length>0){
    
  }else{
alert("请插入正确值");
    return;


  }
  $.ajax({ 
    type:'post', //传送的方式,get/post 
    url:'menueBigAjax.php', //发送数据的地址 
    cache:'false', 
    data:"menueName="+menueName+"&which=0&supplier_location_id="+supplier_location_id, 
    datatype:"text",
    success:function(data) 
    { 
      window.location.reload();
    } 
  }) ;
}



function removeBigMenue(menueid){
  var menueid=menueid;
  if($("#menuenum"+menueid).val()>0){
    alert("请先删除子菜单");
  }else{
  $.ajax({ 
    type:'post', //传送的方式,get/post 
    url:'menueBigAjax.php', //发送数据的地址 
    cache:'false', 
    data:'menueTopid='+menueid+"&which=1",
    datatype:"text",
    success:function(data) 
    { 
      if(data == 'success'){
        $("#ml"+menueid).remove(); 
        $("#bigId"+menueid).remove();
        alert('删除成功');
      }else{
        alert('删除失败，其他店铺在此分类下还有菜品，先不要删除哦');
      }
    } 
  }) ;
  }
}



function updateBigMenue(menueid,which){

if(which==0){
  $("#inputBigName"+menueid).css("display","inline");

  $("#menue2BigName"+menueid).css("display","none");

  $("#menueBigupdate"+menueid).html("保存");
  $("#menueBigupdate"+menueid).attr("href","javascript:updateBigMenue("+menueid+",1)");
}else if (which==1) {
  var menueid=menueid;
  var menueBigName=$("#inputBigName"+menueid).val();

  $.ajax({ 
    type:'post', //传送的方式,get/post 
    url:'menueBigAjax.php', //发送数据的地址 
    cache:'false', 
    data:'menueBigid='+menueid+"&menueBigName="+menueBigName+"&which=2", 
    datatype:"text",
    success:function(data) 
    { 
      if(data == 'success'){
        alert("修改成功");

        $("#inputBigName"+menueid).css("display","none");

        $("#menue2BigName"+menueid).css("display","block");

        $("#menue2BigName"+menueid).html($("#inputBigName"+menueid).val());

        $("#menueBigupdate"+menueid).html("修改");
        $("#menueBigupdate"+menueid).attr("href","javascript:updateBigMenue("+menueid+",0)");
      }else{
        alert("修改失败，请稍后再试");
      }
    } 
  }); 
}
}


function updateMenue(menueid,which){
  if(which==0){
    $("#inputName"+menueid).css("display","block");
    $("#inputPrice"+menueid).css("display","block");
    $("#menue2Name"+menueid).css("display","none");
    $("#menuePrice"+menueid).css("display","none");
    $("#menueupdate"+menueid).html("保存");
    $("#menueupdate"+menueid).attr("href","javascript:updateMenue("+menueid+",1)");
  }else if (which==1) {
    var menueid=menueid;
    var menueName=$("#inputName"+menueid).val();
    var menuePrice=$("#inputPrice"+menueid).val();
    $.ajax({ 
      type:'post', //传送的方式,get/post 
      url:'menueAjax.php', //发送数据的地址 
      cache:'false', 
      data:'menueid='+menueid+"&menueName="+menueName+"&menuePrice="+menuePrice+"&which=2", 
      datatype:"text",
      success:function(data) 
      { 
        alert("修改成功");

        $("#inputName"+menueid).css("display","none");
        $("#inputPrice"+menueid).css("display","none");
        $("#menue2Name"+menueid).css("display","block");
        $("#menuePrice"+menueid).css("display","block");
        $("#menue2Name"+menueid).html($("#inputName"+menueid).val());
        $("#menuePrice"+menueid).html($("#inputPrice"+menueid).val());
        $("#menueupdate"+menueid).html("修改");
        $("#menueupdate"+menueid).attr("href","javascript:updateMenue("+menueid+",0)");
      } 
    }) 

  };
}
function removeMenue(menueid,bid){
  
  var menueid=menueid;
 
  $.ajax({ 
    type:'post', //传送的方式,get/post 
    url:'menueAjax.php', //发送数据的地址 
    cache:'false', 
    data:'menueid='+menueid+"&which=1",
    datatype:"text",
    success:function(data) 
    { 

      if(parseInt($("#menuenum"+bid).val())>0){
        $("#menuenum"+bid).val(parseInt($("#menuenum"+bid).val())-1);
      }
      $("#menueli"+menueid).remove();
      
    } 
  });
}



$(function(){ 
//Default Action 
$(".tab_content").hide(); //Hide all content 
$("ul.tabs li:first").addClass("active").show(); //Activate first tab 
$(".tab_content:first").show(); //Show first tab content 
//On Click Event 
$("ul.tabs li").click(function() { 
$("ul.tabs li").removeClass("active"); //Remove any "active" class 
$(this).addClass("active"); //Add "active" class to selected tab 
$(".tab_content").hide(); //Hide all tab content 
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content 
$(activeTab).fadeIn(); //Fade in the active content 
return false; 
}); 
}); 
</script> 
<script type="text/javascript"> 
$(function(){
$('#login').click(function(){   //给box_btn绑定一个鼠标点击的事件
$.blockUI({    //当点击事件发生时调用弹出层
  message: $('#loginbox'),    //要弹出的元素box
  css: {    //弹出元素的CSS属性
    border:'5px solid #334343',
    textAlign: 'left',
  width: '490px',
  top:  ($(window).height() - 290) /2 + 'px', 
    left: ($(window).width() - 490) /2 + 'px', 
  cursor: 'auto'
       },
  overlayCSS: {
  opacity: '0.7' 
            }
         });
$('.blockOverlay').attr('title','单击关闭').click($.unblockUI);   //遮罩层属性的设置以及当鼠标单击遮罩层可以关闭弹出层
$('.close').click($.unblockUI);  //也可以自定义一个关闭按钮来关闭弹出层

});

});
</script> 
</head>

<body>

<div id="loginbox" style="display:none">
  <div class="login_title">会员登录</div>
  <div class="login_input">
    <div class="input"><span>账号：</span><span><input name="user" type="text" /></span></div>
    <div class="input"><span>密码：</span><span><input name="pwd" type="password" /></span></div>
    <div class="login_input_1 clearfix"><input name="" type="checkbox" value="" id="store1" /><label for="store1">自动登录</label><a href="#">找回密码</a></div>
    <div class="reg clearfix"><span><input class="login_btn" name="" type="image" src="images/login.jpg" /></span><span>还没有账号？</span><a href="#">立即注册</a></div>
  </div>
</div>




<div class="top">
  <div class="top_content clearfix"><span class="left"><a href="index.php"><img src="images/wmwlogo.png"></a></span><span class="right">
 
  <?php
  include('system/db/conn.php');
    if(isset($_SESSION['username'])){
      if($_SESSION['logintype']=="userlog"){
     echo '<a href="member.php">'.$_SESSION['username'],'欢迎你！</a>';
}elseif ($_SESSION['logintype']=="supplierlog") {
   echo '<a href="shop-xx.php">'.$_SESSION['username'],'欢迎你！</a>';
}
      echo '<a href="login.php?action=logout">登出</a>';
    }else{
      echo ' <a href="#" id="login">';
      echo '登录';
      echo '</a> / <a href="reg11.php">注册</a>';
    }
  ?>
  <?php  
      if(!isset($_SESSION['username'])  ){
   ?>
  | <a href="#"  id="shoplogin">店铺登录</a></span></div>
  <?php 
    }

$local_array = mysql_query("select dsl.*,ds.* from do_supplier_location dsl,do_supplier ds where dsl.supplier_id=".$_SESSION['supplierid']." and dsl.supplier_id=ds.id");
$row4 = mysql_fetch_row($local_array);
mysql_free_result($local_array);


   ?>
</div>


<div class="content clearfix">
  <div class="content_con clearfix">
    <div class="box_left left">
      <div class="box">
        <div class="box_title"><div class="box_title_con1 left"><?php echo $_SESSION['username'] ?></div></div>
        <ul class="clearfix box_ul">
          <li><span class="ico5"><a href="shop-xx.php">店铺信息</a></span></li>
         <li><span class="ico6"><a href="shop-dd.php">订单管理</a></span></li>
          <li class="liselect"><span class="ico7select"><a href="shop-cd.php">菜单管理</a></span></li>
          <li><span class="ico4"><a href="shop-pass.php">修改密码</a></span></li>
        </ul>
      </div>
      <div class="box">
        <div class="box_title"><div class="box_title"><div class="box_title_title">销售统计</div></div></div>
        <ul class="clearfix box_ul_1">
          <li> 
            <span>日期</span>
            <span>
              <input type="text" name="open_time2" id="riqiNian" onchange="getAllOrderMoney(<?php echo $_SESSION['supplierid'] ?>)" value="<?php echo date("Y") ?>"  style="width:78px;height:23px;" size="20" onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy'})">年
              
            </span>
            <span>
              <input type="text" name="open_time2"  id="riqiYue" onchange="getAllOrderMoney(<?php echo $_SESSION['supplierid'] ?>)" value="<?php echo date("m") ?>" style="width:22px;height:23px;" size="20" onfocus="WdatePicker({skin:'whyGreen',dateFmt:'MM'})">月
              
            </span>
          </li>
          <li><span class="count_tit">单量</span><span id="fenshu">0</span>份</li>
          <li><span class="count_tit">销售额</span><span id="jiage">0</span>元</li>
          
        </ul>
      </div>
    </div>
    <div class="box_right right">
      <div class="box" >
        <div class="box_title"><div class="box_title_title">菜单管理</div></div>
        



        <div class="box_menu">
        <?php  
          $suoyin=0;
          $another_query = mysql_query("select t.*,b.name as bname,b.id as bid from do_supplier_location_menu_cate b left join do_supplier_location_menu t on t.cate_id =b.id where b.supplier_location_id=".$row4[0]."  GROUP BY  bname  ORDER BY  bid");

          while($rowa = mysql_fetch_array($another_query)){

        ?>
          <div class="menu_title clearfix" id="bigId<?php echo $rowa['bid'] ?>">
            <span class="menu_title_case left" ><input type="text" id="inputBigName<?php echo $rowa['bid'] ?>" onblur="updateBigMenue(<?php echo $rowa['bid'] ?>,1)" style="display:none;height:30px;" value="<?php echo $rowa['bname'] ?>"/><span id="menue2BigName<?php echo $rowa['bid'] ?>"><?php echo $rowa["bname"] ?></span></span>
            <span class="oper right"><a href="javascript:removeBigMenue(<?php echo $rowa['bid'] ?>)">删除</a></span>
            <span class="oper right"><a id="menueBigupdate<?php echo $rowa['bid'] ?>" href="javascript:updateBigMenue(<?php echo $rowa['bid'] ?>,0)">修改</a></span>
          </div>  
          <div class="menu_list" id="ml<?php echo $rowa['bid'] ?>">
            <ul>
              <?php
              $zimenuenum=0;
              if($rowa[1]>0){
                $area_query = mysql_query("select * from do_supplier_location_menu where supplier_location_id=".$rowa[1]." and cate_id=".$rowa[5]." order by id");
             
            
          while($row = mysql_fetch_array($area_query)){
          $zimenuenum+=1;
            $suoyin+=1;

          ?>  
              <li class="clearfix" id="menueli<?php echo $row['id'] ?>">

                <span class="left" id="menuename<?php echo $row['id'] ?>"><input type="text" id="inputName<?php echo $row['id'] ?>"  style="display:none;height:30px;" value="<?php echo $row['name'] ?>"/>  <span id="menue2Name<?php echo $row['id'] ?>"><?php echo $row['name'] ?></span></span>
                <span class="oper right"><a href="javascript:removeMenue(<?php echo $row['id'] ?>,<?php echo $rowa['bid'] ?>)">删除</a></span>
                <span class="oper right"><a id="menueupdate<?php echo $row['id'] ?>" href="javascript:updateMenue(<?php echo $row['id'] ?>,0)">修改</a></span> 
                <span class="price right"><input type="text"   id="inputPrice<?php echo $row['id'] ?>" style="display:none;height:30px;" value="<?php echo  round($row['price'],1) ?>"/><a href="###" id="menuePrice<?php echo $row['id'] ?>"><?php echo  round($row['price'],1) ?></a></span>
              </li>

          <?php 
            }
             mysql_free_result($area_query);
              }
          ?> 

            </ul>
            <input type="hidden" value="<?php echo  $zimenuenum ?>" id="menuenum<?php echo $rowa['bid'] ?>"/>
            <div class="add clearfix">
              <div class="add_dishes clearfix left"><span class="left"><input type="image" src="images/shop_2.jpg" onclick="addMenue(<?php echo $rowa['bid'] ?>,<?php echo $row4[0] ?>)"></span><span class="left"><input type="text" id="menueName<?php echo $rowa['bid'] ?>" class="add_dishes_input"></span></div>
              <div class="clearfix left"><span class="left"></span><span style="padding-left:54px;" class="left"><input type="text" id="menueNum<?php echo $rowa['bid'] ?>" class="add_dishes_input_1"></span></div>
            </div>
            
          </div>
          <?php

  }

?>
 <div class="box_menu" style="padding-bottom:66px;">
          <div class="menu_title clearfix">
            <div style="margin:7px auto 0px auto;width:255px;">
              <span class="left"><input type="image" onclick="addBigMenue(<?php echo $row4[0] ?>)" src="images/shop_5.jpg"></span><span class="left"><input type="text" id="menueBigbName" class="add_dishes_input_2"></span></div>
          </div>
 </div>
  </div>
  </div>
</div>
</div>
</div>
<?php include('bottom.php') ?> 
</body>
</html>

